package com.leruan.aasimp.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.leruan.aasimp.dao.OddDao;
import com.leruan.aasimp.entity.CarOdd;

public class OddDaoImpl extends HibernateDaoSupport implements OddDao{

	public void addOdd(CarOdd odd) {
		Session session = this.getSession();
		session.save(odd);
	}

	public CarOdd getOddByOid(Long oddId) {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarOdd.class);
		Criterion  c1 = Expression.eq("oddId", oddId);
		cri.add(c1);
		CarOdd result = (CarOdd) cri.uniqueResult();
		return result;
	}

	public void updateOdd(CarOdd odd) {
		Session session = this.getSession();
		session.update(odd);
	}

	@SuppressWarnings("unchecked")
	public List<CarOdd> getOdd(String username) {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarOdd.class);
		Criterion  c1 = Expression.eq("personname", username);
		Criterion  c2 = Expression.ne("status", "0");
		cri.add(c1);
		cri.add(c2);
		List<CarOdd> list = cri.list();
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<CarOdd> getOddByCompanyNm(String companyName) {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarOdd.class);
		Criterion  c1 = Expression.eq("oddCompany", companyName);
		Criterion  c2 = Expression.ne("status", "0");
		cri.add(c1);
		cri.add(c2);
		List<CarOdd> list = cri.list();
		return list;
	}

	public List<CarOdd> getPassOddByCompanyNm(String companyName) {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarOdd.class);
		Criterion  c1 = Expression.eq("oddCompany", companyName);
		Criterion  c2 = Expression.eq("status", "2");
		cri.add(c1);
		cri.add(c2);
		List<CarOdd> list = cri.list();
		return list;
	}

}
